package com.wwgsky.basestatusfragment.base

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.wwg.module_base.inter.BaseFragment_Inter

/**
 * 懒加载实现方案 for DataBinding
 */
abstract class LazyFragment4DB : Fragment(),BaseFragment_Inter {

    private lateinit var mContext : Context
    private var isFirstLoad : Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mContext = requireActivity()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val layoutView = getLayoutView(inflater, container, false)
        initView(layoutView)

        return layoutView
    }

    override fun onResume() {
        super.onResume()
        if (isFirstLoad){
            initData()
            setEvent()
            isFirstLoad = false
        }
    }

    /**
     * 初始化布局
     */
    protected open fun initView(view: View?) {}

    /**
     * 初始化数据
     */
    protected open fun initData() {}

    /**
     * 绑定设置监听器、设置执行回调事件等
     */
    protected open fun setEvent() {}

}